package com.lambda.cloud;

import com.lambda.cloud.core.convert.BaseConverter;
import com.lambda.cloud.core.resolver.ConverterResolver;
import com.lambda.cloud.domain.UserCreateDTO;
import com.lambda.cloud.domain.UserEntity;
import com.lambda.cloud.domain.UserVO;
import java.time.LocalDateTime;
import java.util.Map;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public ApplicationRunner applicationRunner() {
        return args -> {
            UserCreateDTO userCreateDTO = new UserCreateDTO();
            userCreateDTO.setCreateTime(LocalDateTime.now());
            userCreateDTO.setUsername("AAA");
            userCreateDTO.setProps(Map.of("CCC", "DDD"));
            UserEntity entity = userCreateDTO.toEntity();
            System.out.printf(entity.getProps());

            BaseConverter<UserEntity, UserVO> converter = ConverterResolver.getConverter(UserVO.class);
            UserVO object = converter.convertTo(entity);
            System.out.printf(object.toString());
        };
    }
}
